import 'package:flutter/material.dart';
import 'package:flutter_k_chart/chart_style.dart';

class ChartTheme extends InheritedTheme {
  final ChartStyle? chartStyle;
  final ChartColors? chartColors;

  const ChartTheme(
      {Key? key, this.chartStyle, this.chartColors, required Widget child})
      : super(key: key, child: child);

  static ChartTheme? of(BuildContext context) {
    return context.dependOnInheritedWidgetOfExactType<ChartTheme>();
  }

  @override
  bool updateShouldNotify(covariant ChartTheme oldWidget) {
    return oldWidget.chartStyle != this.chartStyle ||
        oldWidget.chartColors != this.chartColors;
  }

  @override
  Widget wrap(BuildContext context, Widget child) {
    final ChartTheme? chartTheme =
        context.findAncestorWidgetOfExactType<ChartTheme>();
    return identical(this, chartTheme)
        ? child
        : ChartTheme(
            chartColors: chartColors,
            chartStyle: chartStyle,
            child: child,
          );
  }
}
